package bb.lanxing.util.ui;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.graphics.Matrix;
import android.view.View;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.jobs.AnimatedZoomJob;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.ViewPortHandler;

public class ChartAnimatedZoomJob extends AnimatedZoomJob {
    public ChartAnimatedZoomJob(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xAxisRange, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
        super(viewPortHandler, v, trans, axis, xAxisRange, scaleX, scaleY, xOrigin, yOrigin, zoomCenterX, zoomCenterY, zoomOriginX, zoomOriginY, duration);
    }

    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
        updateZoomAndPos();
    }

    @Override
    public void onAnimationEnd(Animator animation) {
        updateZoomAndPos();
        super.onAnimationEnd(animation);
    }

    private void updateZoomAndPos() {
        float f = this.xOrigin + ((this.xValue - this.xOrigin) * this.phase);
        float f2 = this.yOrigin + ((this.yValue - this.yOrigin) * this.phase);
        Matrix matrix = this.mOnAnimationUpdateMatrixBuffer;
        this.mViewPortHandler.setZoom(f, f2, matrix);
        this.mViewPortHandler.refresh(matrix, this.view, false);
        float scaleY = this.yAxis.mAxisRange / this.mViewPortHandler.getScaleY();
        this.pts[0] = this.zoomOriginX + (((this.zoomCenterX - ((this.xAxisRange / this.mViewPortHandler.getScaleX()) / 2.0f)) - this.zoomOriginX) * this.phase);
        this.pts[1] = this.zoomOriginY + (((this.zoomCenterY + (scaleY / 2.0f)) - this.zoomOriginY) * this.phase);
        this.mTrans.pointValuesToPixel(this.pts);
        this.mViewPortHandler.translate(this.pts, matrix);
        this.mViewPortHandler.refresh(matrix, this.view, true);
    }
}
